Skip to content

fix(tui): resolve shell carriage-return redraws#1548

Open
starSumi wants to merge 2 commits into
MoonshotAI:mainfrom
starSumi:fix/shell-carriage-return-redraw
Open

fix(tui): resolve shell carriage-return redraws#1548
starSumi wants to merge 2 commits into
MoonshotAI:mainfrom
starSumi:fix/shell-carriage-return-redraw

Conversation

@starSumi

Copy link
Copy Markdown

Related Issue

No linked issue. This is a focused bug fix for shell output that redraws the current terminal line with carriage returns.

Problem

Captured shell output is sanitized before pi-tui renders it. The sanitizer currently removes carriage returns as ordinary control characters, so redraw sequences such as frame1\rframe2\rframe3 become frame1frame2frame3 instead of the terminal-visible final frame, frame3.

That makes progress output grow and wrap unnecessarily in the live and final shell output views.

What changed

Resolve carriage-return redraws after stripping terminal escape sequences and before removing other C0 control characters. This keeps CRLF line endings as newlines while simulating same-line overwrite behavior for progress updates.

Added regression coverage for equal-length redraws, shorter partial overwrites, and CRLF normalization.

Validation

  • pnpm --filter @moonshot-ai/kimi-code exec vitest run test/tui/utils/shell-output.test.ts
  • pnpm exec oxlint apps/kimi-code/src/tui/utils/shell-output.ts apps/kimi-code/test/tui/utils/shell-output.test.ts
  • pnpm --filter @moonshot-ai/kimi-code run typecheck

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jul 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ff70fc9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 99f5dc7c2c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +56 to +58
.replace(CSI_PATTERN, '')
.replace(ESC_SINGLE_PATTERN, '')
.replace(C0_CONTROL_PATTERN, '');
.replace(ESC_SINGLE_PATTERN, '');
return resolveCarriageReturns(withoutEscapes).replace(C0_CONTROL_PATTERN, '');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor erase-in-line when resolving carriage returns

For redraws that clear the current line, such as Downloading 100%\rDone\u001b[K or Downloading 100%\r\u001b[KDone, this strips ESC[K before simulating the carriage return, so resolveCarriageReturns preserves the old suffix and produces output like Doneloading 100% instead of the terminal-visible Done. This affects common progress renderers that combine \r with erase-in-line, leaving stale tails in the live and final shell output views.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant